<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2019-11-25
 * Time: 16:37
 */

namespace app\api\controller\v1;

use app\api\controller\BaseController;
use app\api\model\BannerItem;
use app\api\validate\IdMustBePositiveInt;
use app\api\model\Banner as BannerModel;
use app\lib\exception\MissException;

class Banner extends BaseController
{
    protected $beforeActionList = [
        'checkPrimaryScope' => ['only' => 'getBanner,getBannerItem']
    ];

    /**
     * 获取指定ID的banner信息
     * @id 1.首页banner
     * @url /banner/:id
     * @http GET
     */
    public function getBanner($id)
    {
        (new IdMustBePositiveInt())->goCheck();
        $banner = BannerModel::getBannerId($id);
        if(!$banner)
        {
            throw new MissException([
                'msg' => '请求banner图不存在',
                'errorCode' => 20000
            ]);
        }
        return $banner;
    }

    /**
     * 获取 bannerItem 详情
     */
    public function getBannerItem($id)
    {
        (new IdMustBePositiveInt())->goCheck();
        $info = BannerItem::get($id);
        return $info;
    }
}